﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Zerg
{
	public class ActionDoubleExtractorTrick : ActionProduceDrone
	{
		public static new ActionDoubleExtractorTrick Instance = new ActionDoubleExtractorTrick();
		private ActionDoubleExtractorTrick() : base() { }
		public override bool HaveTechnology(IBuildOrder bo) { return true; }
		public override void OnProductionFinished(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			state.Drone++;
			state.Drone_Building--;
			state.WorkersOnMinerals++;
		}
		public override bool HaveResources(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			return
				state.Extractor.Total + 2 <= bo.State.Bases.Total * 2 &&
				AvailableProducer(bo) > 1 &&
				bo.State.Minerals >= (Minerals + 25) * 2 &&
				bo.State.Supply == bo.State.Food;
		}
		public override bool IsInvalid(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			if (bo.State.Supply != bo.State.Food) return true;
			if (state.Extractor.Total + 2 > bo.State.Bases.Total * 2) return true;
			if (bo.State.Minerals < (Minerals + 25) * 2 && bo.State.WorkersOnMinerals == 0) return true;
			return false;
		}
		public override string EventName { get { return "ActionSpawnDrone"; } }
		public override void Execute(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			bo.State.Minerals -= Minerals * 2;
			bo.State.Food += Food * 2;
			state.UseLarva(bo);
			state.UseLarva(bo);
			state.Drone_Building+=2;
			bo.AddAction(state.Time + BuildTime, new ActionGeneric(EventName, (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				ZergState ibostate = ibo.State as ZergState;
				OnProductionFinished(ibo);
			}));
			bo.AddAction(state.Time + BuildTime, new ActionGeneric(EventName, (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				ZergState ibostate = ibo.State as ZergState;
				OnProductionFinished(ibo);
			}));
		}
	}
}
